package cn.yunhe.service.serviceImpl;

import cn.yunhe.dao.OrderDao;
import cn.yunhe.entity.Orders;
import cn.yunhe.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDao orderDao;

    @Override
    public List<Orders> findAll() {
        return orderDao.findAll();
    }

    @Override
    public void insertOrders(Orders orders) {
        orderDao.insertOrders(orders);
        Integer id = orders.getId();
        List<Integer> travellerId = orders.getTravellerId();
        for (Integer traverID : travellerId) {
            orderDao.insertOt(id, traverID);
        }
    }

    @Transactional
    @Override
    public void deleteById(Integer id) {
        orderDao.deleteOtById(id);
        orderDao.deleteById(id);


    }

    @Override
    public Orders selectById(Integer id) {
        return orderDao.selectById(id);
    }

    @Override
    public void updateById(Orders orders) {
        orderDao.updateById(orders);
    }

    @Override
    public Orders findById(Integer id) {
        return orderDao.findById(id);
    }

    @Transactional
    @Override
    public void selectDelete(Integer[] ids) {
        for (int i = 0; i < ids.length; i++) {
            orderDao.deleteOtById(ids[i]);
            orderDao.deleteById(ids[i]);

        }
    }


}
